package org.rabbitmq.test6;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import org.rabbitmq.utils.RabbitMqUtils;

/**
 * 消息接收
 */
public class ReceiveLogs02 {

    public static final String EXCHANGE_NAME = "direct_logs";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();
        //声明一个交换机
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.DIRECT);
        //声明一个临时队列
        /**
         * 生产一个临时队列，队列名称随机
         * 消费者断开与队列连接，队列自动删除
         */
        channel.queueDeclare("disk",false,false,false,null);
        /**
         * 绑定交换机与队列
         */
        channel.queueBind("disk",EXCHANGE_NAME,"error");


        System.out.println("等等接收消息，接收到的消息打印出来");

        //接收消息
        DeliverCallback deliverCallback = (consumerTag, message)->{
            System.out.println("02接收到"+ new String(message.getBody(), "UTF-8"));
        };
        //取消消息时触发
        channel.basicConsume("disk",true,deliverCallback,consumerTag->{});
    }
}
